package com.atguigu.lease.web.admin.controller.task;

import com.atguigu.lease.model.entity.LeaseAgreement;
import com.atguigu.lease.model.enums.LeaseStatus;
import com.atguigu.lease.web.admin.service.LeaseAgreementService;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.util.Date;

/**
 * @version 1.0
 * @date2024/9/13 20:16
 */
@Component
public class checkAndUpdateStatementTask {
    @Autowired
    private LeaseAgreementService leaseAgreementService;

    @Scheduled(cron = "0 52 20 * * ?")
    public void checkAndUpdate(){
        LambdaUpdateWrapper<LeaseAgreement> leaseAgreementLambdaUpdateWrapper = new LambdaUpdateWrapper<>();
        //查询过期时间在现在时间之前且状态为2，5，7的更改为过期
        leaseAgreementLambdaUpdateWrapper.le(LeaseAgreement::getLeaseEndDate, new Date())
                .in(LeaseAgreement::getStatus,2,5,7)
                .set(LeaseAgreement::getStatus, LeaseStatus.EXPIRED);
        leaseAgreementService.update(leaseAgreementLambdaUpdateWrapper);
    }
}
